package cn.csc.framework.pay.core.client.impl.tl;

import cn.csc.framework.pay.core.client.impl.tl.util.SybPayService;
import com.alibaba.fastjson.JSONObject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Map;

import static cn.csc.framework.test.core.util.RandomUtils.randomPojo;


public class ApiTestV2 {

    protected SybPayService payService;

    protected TLPayClientConfig config = randomPojo(TLPayClientConfig.class, o -> {
        o.setAppId("OP00000003");
        o.setMchId("00dfba8194c41b84cf");
        o.setWxMchId("8221210594300JY");
        o.setOrgId("A0073841");
        o.setSignType("RSA");
        o.setPrivateKey(privateKey);

        o.setServerUrl(AbstractTLClient.SERVER_URL_TEST);
    });

    @BeforeEach
    public void setUp(){
        payService = new SybPayService( config);
    }

	

	@Test
	public void testScanPay() throws Exception {
		String reqsn = String.valueOf(System.currentTimeMillis());
		Map<String, String> map = payService.scanPay(1, reqsn,  "标题", "备注",  "134775931316089668","","","","");
		print(map);
	}

    @Test
	public void testQuery() throws Exception{
		JSONObject map = payService.query("", "112094120001088317");
        System.out.println(map);
    }

    @Test
	public void testRefund() throws Exception{
		String reqsn = String.valueOf(System.currentTimeMillis());
		//Map<String, String> map = service.refund(1, reqsn, "", "20160712167578.2547");
		//print(map);
	}

    @Test
	public void testCancel() throws Exception{
		String reqsn = String.valueOf(System.currentTimeMillis());
		Map<String, String> map = payService.cancel(1, reqsn, "112094120001088316", "");
		print(map);
	}

    @Test
	public void testPay() throws Exception{
		String reqsn = String.valueOf(System.currentTimeMillis());
		Map<String, String> map = payService.pay(1, reqsn, "W01", "标题", "备注", "", "123","https://test.allinpaygd.com/JWeb/NotifyServlet","","","","", "", "", "", "", "", "", "","","","","","","");
		print(map);
	}
	
	public static void print(Map<String, String> map){
		System.out.println("返回数据如下:");
		if(map!=null){
			for(String key:map.keySet()){
				System.out.println(key+";"+map.get(key));
			}
		}
	}
	
	private static final String privateKey = "";
}
